package com.api.signature.auto.client.spring;

import com.api.signature.auto.client.config.SignConfigClient;
import com.api.signature.auto.client.util.ClientSignUtil;
import com.signature.auto.common.util.ApiFoxUtil;
import com.signature.auto.common.util.SignUtil;

/**
 * @author Jerry
 * @date 2024-01-24 11:07
 * 管理 api签名 所有全局组件，可通过此类快速获取、写入各种全局组件对象
 */
public class ApiClientSignContext {


    public volatile static SignConfigClient signConfigClient;

    public static void setConfig(SignConfigClient config) {
        setConfigMethod(config);
        // 打印 banner
        if (config != null && config.getIsPrint()) {
            ApiFoxUtil.printApiClientSignature();
        }
    }

    private static void setConfigMethod(SignConfigClient config) {
        ApiClientSignContext.signConfigClient = config;
    }

    private volatile static ClientSignUtil signUtil;

    public static SignUtil getSignUtil() {
        if (signUtil == null) {
            synchronized (ApiClientSignContext.class) {
                if (signUtil == null) {
                    signUtil = new ClientSignUtil();
                }
            }
        }
        return signUtil;
    }


}
